#include "StdAfx.h"
#include "cEffect.h"
#include "AnimSequence.h"

//--------------------------------------------------------------------------------------------------------------------------------------------
cEffect::cEffect(void)
{
	mbLoop = FALSE;
	mbPlayed = FALSE;
	mLimitTime = 0;
	fEleapsedTime = 0.f;
	mCurrentFrame = 0;
	mSprite = NULL;

	gGameTime.Init();
}
//--------------------------------------------------------------------------------------------------------------------------------------------
cEffect::~cEffect(void)
{
	mSprite->release();
	SAFE_DELETE( mSprite );
}
//--------------------------------------------------------------------------------------------------------------------------------------------
void cEffect::Init( AnimSequence* s, FLOAT limittime, float scale  )
{
	mSprite = s;
	mSprite->SetScale( scale );
	mLimitTime = limittime;
}
//--------------------------------------------------------------------------------------------------------------------------------------------
void cEffect::update(float dt)
{
	gGameTime.Update();

	if (mbPlayed)
	{
		fEleapsedTime += gGameTime.elapsedTime;

		if ( fEleapsedTime > mLimitTime)
		{
			fEleapsedTime = 0.f;
			mCurrentFrame = 0;
			if (!mbLoop)
			{
				mbPlayed = FALSE;
			}
		}
		else
		{
			mCurrentFrame = fEleapsedTime / (mLimitTime) / (FLOAT)mSprite->getTotalFrame();
		}
	}
}
//--------------------------------------------------------------------------------------------------------------------------------------------
void cEffect::Play( D3DXVECTOR3 getPosition ,BOOL loop)
{
	Setpos( getPosition );
	mbLoop = loop;
	mbPlayed = TRUE;
}
//--------------------------------------------------------------------------------------------------------------------------------------------
void cEffect::render( )
{
	if (mbPlayed)
 	{
		mSprite->SetScale( mCurrentFrame );
		mSprite->Render( position.x, position.y, position.z ); 
	}
}
//--------------------------------------------------------------------------------------------------------------------------------------------
